import { _ as _export_sfc, x as useMainStore, y as storeToRefs, z as ref, al as useNavbarHeight, A as computed, B as onLoad, a1 as navigateTo, R as onPullDownRefresh, aa as onReachBottom, a5 as showLoading, W as stopPullDownRefresh, a7 as hideLoading, g as createElementBlock, b as createVNode, w as withCtx, n as normalizeStyle, H as unref, F as Fragment, j as resolveEasycom, i as index$g, G as __easycom_0, k as resolveDynamicComponent, o as openBlock, c as createBlock, e as createCommentVNode, h as renderList, t as createTextVNode, u as toDisplayString, p as index$q, X as formatDateTime, Q as index$x, M as withModifiers, ag as navigateBack } from './index-Cc4oxzDN.js';
import { _ as __easycom_1 } from './uv-tabs.CwA-F7oh.js';
import { _ as __easycom_2 } from './list-cell.BHNnBKKp.js';
import { _ as __easycom_4 } from './uv-empty.ob-CT4XT.js';
import { o as orderGetOrders, a as orderReceive } from './order.D8qtvuIN.js';
import './uv-badge.D4nY_Rjy.js';
import './platform.EIa5ETLd.js';

const _sfc_main = {
  __name: 'orders',
  setup(__props) {

	const main = useMainStore();
	const {
		isLogin
	} = storeToRefs(main);
	const title = ref('我的订单');
	
	// 获取导航栏高度
	const { navbarHeightCss } = useNavbarHeight();

	// 返回上一页
	const $onClickLeft = () => {
		navigateBack();
	};

	const page = ref(1);
	const pageSize = ref(10);
	const orders = ref([]);
	const tabList = ref([{
		type: -1,
		name: '全部',
	}, {
		type: 0,
		name: '待支付',
	}, {
		type: 1,
		name: '进行中'
	}, {
		type: 4,
		name: '已完成'
	}, {
		type: -3,
		name: '退款单'
	}]);
	const current = ref(0);
	const type = ref(-1);

	const goodsNum = computed(() => { //计算单个饮品添加到购物车的数量
		return (goods) => {
			let num = 0;
			goods.forEach(good => num += parseInt(good.number));
			return num;
		}
	});
	
	// 判断是否显示确认收到餐按钮
	const shouldShowReceiveButton = computed(() => {
		return (item) => {
			// 订单状态说明：
			// 0: 待支付
			// 1: 已支付/制作中
			// 2: 配送中/待取餐
			// 3: 已送达/可取餐
			// 4: 已完成
			
			// 只有已支付且状态为配送中/待取餐的订单才显示确认收到餐按钮
			return item.paid > 0 && 
				   item.status >= 2 && 
				   item.status < 4 && 
				   item.refundStatus == 0
		}
	});
	onLoad(() => {
		if (!isLogin.value) {
			navigateTo({
				url: '/pages/login/login'
			});
		}
		getOrders(false);
	});
	onPullDownRefresh(() => {
		getOrders(false);
	});
	onReachBottom(() => {
		getOrders(false);
	});

	// tab栏切换
	const change = (e) => {
		type.value = e.type;
		getOrders(true);
	};

	const getOrders = async (isRefresh = false) => {
		showLoading({
			title: '加载中'
		});
		if (isRefresh) {
			orders.value = [];
			page.value = 1;
		}
		let ordersData = await orderGetOrders({
			page: page.value,
			limit: pageSize.value,
			type: type.value
		});

		if (ordersData) {
			orders.value = orders.value.concat(ordersData);
			page.value += 1;
		}
		stopPullDownRefresh();
		hideLoading();
	};
	const detail = (id) => {
		navigateTo({
			url: '/pages/components/pages/orders/detail?id=' + id
		});
	};
	// 确认收到货
	const receive = async (order) => {
		let data = await orderReceive({
			uni: order.orderId
		});
		if (data) {
			await getOrders(true);
		}
	};

return (_ctx, _cache) => {
  const _component_uv_navbar = resolveEasycom(resolveDynamicComponent("uv-navbar"), __easycom_0);
  const _component_uv_tabs = resolveEasycom(resolveDynamicComponent("uv-tabs"), __easycom_1);
  const _component_v_uni_view = index$g;
  const _component_list_cell = resolveEasycom(resolveDynamicComponent("list-cell"), __easycom_2);
  const _component_v_uni_image = index$q;
  const _component_v_uni_button = index$x;
  const _component_uv_empty = resolveEasycom(resolveDynamicComponent("uv-empty"), __easycom_4);

  return (openBlock(), createElementBlock(Fragment, null, [
    createVNode(_component_uv_navbar, {
      fixed: true,
      title: title.value,
      "left-arrow": "",
      onLeftClick: $onClickLeft
    }, null, 8, ["title"]),
    createVNode(_component_v_uni_view, {
      class: "container",
      style: normalizeStyle(`padding-top: ${unref(navbarHeightCss)};`)
    }, {
      default: withCtx(() => [
        createVNode(_component_v_uni_view, { class: "bg-white" }, {
          default: withCtx(() => [
            createVNode(_component_uv_tabs, {
              list: tabList.value,
              current: current.value,
              onChange: change,
              keyName: "name",
              scrollable: false
            }, null, 8, ["list", "current"])
          ]),
          _: 1
        }),
        createVNode(_component_v_uni_view, {
          class: "orders-list d-flex flex-column w-100",
          style: {"padding":"20rpx","padding-bottom":"0"}
        }, {
          default: withCtx(() => [
            (openBlock(true), createElementBlock(Fragment, null, renderList(orders.value, (item, index) => {
              return (openBlock(), createBlock(_component_v_uni_view, {
                class: "order-item",
                key: index,
                style: {"margin-bottom":"30rpx"},
                onClick: $event => (detail(item.orderId))
              }, {
                default: withCtx(() => [
                  createVNode(_component_list_cell, { hover: false }, {
                    default: withCtx(() => [
                      createVNode(_component_v_uni_view, { class: "w-100 d-flex align-items-center" }, {
                        default: withCtx(() => [
                          (item.shop)
                            ? (openBlock(), createBlock(_component_v_uni_view, {
                                key: 0,
                                class: "flex-fill d-flex flex-column"
                              }, {
                                default: withCtx(() => [
                                  createVNode(_component_v_uni_view, {
                                    class: "font-size-lg text-color-base",
                                    style: {"margin-bottom":"20rpx"}
                                  }, {
                                    default: withCtx(() => [
                                      createTextVNode(toDisplayString((item.shop && item.shop.name !== undefined && item.shop.name !== null) ? item.shop.name : '无'), 1)
                                    ]),
                                    _: 2
                                  }, 1024),
                                  createVNode(_component_v_uni_view, { class: "font-size-sm text-color-assist" }, {
                                    default: withCtx(() => [
                                      createTextVNode("取餐号：" + toDisplayString(item.numberId), 1)
                                    ]),
                                    _: 2
                                  }, 1024),
                                  createVNode(_component_v_uni_view, { class: "font-size-sm text-color-assist" }, {
                                    default: withCtx(() => [
                                      createTextVNode("订单编号：" + toDisplayString(item.orderId), 1)
                                    ]),
                                    _: 2
                                  }, 1024)
                                ]),
                                _: 2
                              }, 1024))
                            : (openBlock(), createBlock(_component_v_uni_view, {
                                key: 1,
                                class: "flex-fill d-flex flex-column"
                              }, {
                                default: withCtx(() => [
                                  createVNode(_component_v_uni_view, { class: "font-size-sm text-color-assist" }, {
                                    default: withCtx(() => [
                                      createTextVNode("订单编号：" + toDisplayString(item.orderId), 1)
                                    ]),
                                    _: 2
                                  }, 1024)
                                ]),
                                _: 2
                              }, 1024)),
                          createVNode(_component_v_uni_view, { class: "font-size-lg text-color-primary" }, {
                            default: withCtx(() => [
                              createTextVNode(toDisplayString(item.statusDto.title), 1)
                            ]),
                            _: 2
                          }, 1024)
                        ]),
                        _: 2
                      }, 1024)
                    ]),
                    _: 2
                  }, 1024),
                  createVNode(_component_list_cell, {
                    hover: false,
                    last: ""
                  }, {
                    default: withCtx(() => [
                      createVNode(_component_v_uni_view, { class: "w-100 d-flex flex-column" }, {
                        default: withCtx(() => [
                          createVNode(_component_v_uni_view, {
                            class: "w-100 text-truncate font-size-lg text-color-base",
                            style: {"margin-bottom":"20rpx"}
                          }, {
                            default: withCtx(() => [
                              (openBlock(true), createElementBlock(Fragment, null, renderList(item.cartInfo, (good, index) => {
                                return (openBlock(), createBlock(_component_v_uni_view, {
                                  class: "flex mb-2",
                                  key: index
                                }, {
                                  default: withCtx(() => [
                                    createVNode(_component_v_uni_image, {
                                      src: good.image,
                                      mode: "aspectFill",
                                      class: "image"
                                    }, null, 8, ["src"]),
                                    createVNode(_component_v_uni_view, { class: "flex flex-column" }, {
                                      default: withCtx(() => [
                                        createVNode(_component_v_uni_view, { class: "font-size-medium mt-1 text-color-base" }, {
                                          default: withCtx(() => [
                                            createTextVNode(toDisplayString(good.title), 1)
                                          ]),
                                          _: 2
                                        }, 1024),
                                        createVNode(_component_v_uni_view, { class: "font-size-sm mt-1" }, {
                                          default: withCtx(() => [
                                            createTextVNode(toDisplayString(good.spec), 1)
                                          ]),
                                          _: 2
                                        }, 1024),
                                        createVNode(_component_v_uni_view, { class: "font-size-sm mt-2" }, {
                                          default: withCtx(() => [
                                            createTextVNode("×" + toDisplayString(good.number) + " ¥" + toDisplayString(good.price), 1)
                                          ]),
                                          _: 2
                                        }, 1024)
                                      ]),
                                      _: 2
                                    }, 1024)
                                  ]),
                                  _: 2
                                }, 1024))
                              }), 128))
                            ]),
                            _: 2
                          }, 1024),
                          createVNode(_component_v_uni_view, {
                            class: "d-flex justify-content-between align-items-center",
                            style: {"margin-bottom":"30rpx"}
                          }, {
                            default: withCtx(() => [
                              createVNode(_component_v_uni_view, { class: "font-size-sm text-color-assist" }, {
                                default: withCtx(() => [
                                  createTextVNode(toDisplayString(unref(formatDateTime)(item.createTime)), 1)
                                ]),
                                _: 2
                              }, 1024),
                              createVNode(_component_v_uni_view, { class: "d-flex font-size-sm text-color-base align-items-center" }, {
                                default: withCtx(() => [
                                  createVNode(_component_v_uni_view, { style: {"margin-right":"10rpx"} }, {
                                    default: withCtx(() => [
                                      createTextVNode("共" + toDisplayString(goodsNum.value(item.cartInfo)) + "件商品，实付", 1)
                                    ]),
                                    _: 2
                                  }, 1024),
                                  createVNode(_component_v_uni_view, { class: "font-size-lg" }, {
                                    default: withCtx(() => [
                                      createTextVNode("￥" + toDisplayString(item.payPrice), 1)
                                    ]),
                                    _: 2
                                  }, 1024)
                                ]),
                                _: 2
                              }, 1024)
                            ]),
                            _: 2
                          }, 1024),
                          createVNode(_component_v_uni_view, { class: "d-flex align-items-center justify-content-end" }, {
                            default: withCtx(() => [
                              createVNode(_component_v_uni_view, null, {
                                default: withCtx(() => [
                                  (shouldShowReceiveButton.value(item))
                                    ? (openBlock(), createBlock(_component_v_uni_button, {
                                        key: 0,
                                        class: "left-margin",
                                        plain: "",
                                        size: "min",
                                        onClick: withModifiers($event => (receive(item)), ["stop"])
                                      }, {
                                        default: withCtx(() => [
                                          createTextVNode("确认收到餐")
                                        ]),
                                        _: 2
                                      }, 1032, ["onClick"]))
                                    : createCommentVNode("", true),
                                  createVNode(_component_v_uni_button, {
                                    class: "left-margin",
                                    plain: "",
                                    size: "min",
                                    onClick: $event => (detail(item.orderId))
                                  }, {
                                    default: withCtx(() => [
                                      createTextVNode("订单详情")
                                    ]),
                                    _: 2
                                  }, 1032, ["onClick"])
                                ]),
                                _: 2
                              }, 1024)
                            ]),
                            _: 2
                          }, 1024)
                        ]),
                        _: 2
                      }, 1024)
                    ]),
                    _: 2
                  }, 1024)
                ]),
                _: 2
              }, 1032, ["onClick"]))
            }), 128))
          ]),
          _: 1
        }),
        (orders.value.length == 0)
          ? (openBlock(), createBlock(_component_uv_empty, {
              key: 0,
              mode: "order"
            }))
          : createCommentVNode("", true)
      ]),
      _: 1
    }, 8, ["style"])
  ], 64))
}
}

};
const orders = /*#__PURE__*/_export_sfc(_sfc_main, [['__scopeId',"data-v-6ba9dd45"]]);

export { orders as default };
